failat 21

if not exists XEN-Icons
  echo "*n Please change current directory to that of MagicWB *n or start the installation from the Workbench!*n"
  quit
endif

assign Magic: ""

echo "*n*e[1;32m ____________________________________________________________________"
echo " *e[43m                                                                    *e[0m"
echo " *e[0;32;43m              Welcome to MagicWB v1.2p: UPDATE DRAWERS*e[1m              *e[0m"
echo " *e[1;4;43m                                                                    *e[0m"
echo "*n*n This small installation was written to provide you with the most"
echo " comfortable way of replacing the old Drawer-Icons with the new ones"
echo " from *e[32mMagicWB*e[0m."
echo " *n This installation should be started AFTER the main installation"
echo " was done IF you still find any old drawers on your Workbench! As"
echo " the main installation only updates the drawers in your SYS-Directory"
echo " there might be the possibility that you still do have old drawers"
echo " in other directories."
echo " *n If you have found old drawers on your Workbench, please remember"
echo " the PATH where they are located to provide this installation with" 
echo " the exact path so that it can update these drawers."
echo " *n Comment: This installation WILL PRESERVE the original positions"
echo " of your old drawers. Only the old Drawer-Images will be changed."
echo " So, don't be afraid. You will NOT lose your old drawer snapshots. ;)"
echo noline "*n Start the Drawer-Update? "

set > nil: InpVar ?

if $InpVar eq "ja"
  skip Start
endif

if $InpVar eq "j"
  skip Start
endif

if $InpVar eq "y"
  skip Start
endif

if $InpVar eq "yes"
  skip Start
endif

echo noline "*n*e[32m Update aborted."
quit

lab Start
resident IU update/IconUpdate pure
echo "*e[1;1H*e[J"
echo "*n Information: You can always abort this installation by pressing"
echo " CTRL-D (and, if needed, followed by pressing RETURN).*n"
echo "*n You can decide now if you want to update the drawers ONLY"
echo " IN THE DIRECTORY of the given path (= Normal mode) or INCLUDING"
echo " ALL SUB-DIRECTORIES of the given path (= Recursive mode).*n"
echo " If you want to do it in the normal mode enter [32mN[0m."
echo " If you want to do it recursively enter [32mR[0m."
echo noline "*n Which mode do you prefer? *e[32m"
set Mode [Return]
set > NIL: Mode ?
if $Mode eq "N"
  skip PathN
endif
if $Mode eq "R"
  skip PathR
endif
echo "[32m*n You have not selected the correct mode! Please try again...[0m"
wait 4
skip back Start

lab PathN
echo noline "*e[0m*n*N Please enter the PATH where old Drawer-Icons are located: *e[32m"
set > NIL: Path ?
echo noline "*e[0m"
  if > NIL: not exists $Path
    echo " Wrong path, `$path' does not exist! Try again...*n"
    skip back PathN
  endif
echo noline "*n Updating Drawer-Icons in $Path ..."
list > ram:MWB $Path dirs lformat "if exists *"%s%s.info*" *nIU > NIL: cw XEN-Icons/Prefs/Env-Archive/Sys/def_Drawer.info *"%s%s.info*" *nendif*n"
execute > NIL: ram:MWB
if warn
  echo " Update has failed!!!"
  skip end
endif
echo "....*e[33mDONE*e[0m"
echo "*n*n*e[32m Drawer-Update successfully finished!*e[0m"
skip prefs

lab PathR
echo noline "*e[0m*n*N Please enter the PATH where old Drawer-Icons are located: *e[32m"
set > NIL: Path ?
echo noline "*e[0m"
  if > NIL: not exists $Path
    echo " Wrong path, `$path' does not exist! Try again...*n"
    skip back PathR
  endif
echo noline "*n Recursively updating Drawer-Icons in $Path ..."
list > ram:MWB $Path dirs all lformat "if exists *"%s%s.info*" *nIU > NIL: cw XEN-Icons/Prefs/Env-Archive/Sys/def_Drawer.info *"%s%s.info*" *nendif*n"
execute > NIL: ram:MWB
if warn
  echo " Update has failed!!!"
  skip end
endif
echo "....*e[33mDONE*e[0m"
echo "*n*n*e[32m Drawer-Update successfully finished!*e[0m"

lab prefs
cd $Path
list > RAM:MWB Prefs.info lformat "%L"
search >NIL: RAM:MWB 2273
if not warn
  wait 3
  echo "*e[1;1H*e[J"
  echo "*n*n Unfortunately you updated the drawers in your SYS: directory!"
  echo " As I told you at the beginning, this had already been done by the"
  echo " main installation. Because you did this for a second time now,"
  echo " the previously installed Prefs-Icon has been overwritten and been"
  echo " replaced by a boring Drawer-Icon. But don't worry:*n"
  echo " You can now decide (again) which type of Prefs-Icon you want to be"
  echo " installed to your SYS: directory. Please type either *"SMALL*" or"
  echo " *"BIG*" in the following request..."
  lab Retry
  echo noline "*e[0m*n Which type of Prefs-Icon should be installed? *e[32m"
  set > NIL: Prefs ?
  if $Prefs eq "SMALL"
    Echo noline "*e[0m Installing SMALL Prefs-Icon..."
    IU > NIL: cw Magic:XEN-Icons/SPECIAL/Prefs.info Prefs.info
    echo "..*e[33mDONE*e[0m"
  else
    if $Prefs eq "BIG"
      Echo noline "*e[0m Installing BIG Prefs-Icon..."
      IU > NIL: cw Magic:XEN-Icons/SPECIAL/Prefs2.info Prefs.info
      echo "..*e[33mDONE*e[0m"
      skip OK
    endif
  echo " You MUST enter either *"SMALL*" or *"BIG*"! Try again..."
  skip back Retry
  endif
  lab OK
endif

if exists Trashcan.info
  IU > NIL: cw Magic:XEN-Icons/Prefs/Env-Archive/Sys/def_trashcan.info Trashcan.info
endif

echo "*n*n*e[32m Everything is OK now. Bye!"

lab end
resident IU remove
delete > NIL: ram:MWB
assign Magic: remove
wait 4
quit
